package com.hisense.hiioc.hismartplate.utils;

import java.util.UUID;

/**
 * @Auther:biexiande@hisense.com
 * @date:2018/12/17 14:49
 * @des
 */
public class UUIDGenerator {
    /**
     * 生成UUID公用业务方法
     */
    public static String createKey() {
        return UUID.randomUUID().toString();
    }

    /**
     * 创建32位的UUID
     */
    public static String create32Key() {
        return UUID.randomUUID().toString().replaceAll("\\-", "");
    }

    /**
     * 创建指定数量的随机字符串
     *
     * @param length
     * @return
     */
    public static int createRandom(int length) {
        String retStr = "";
        String strTableFirst = "123456789";
        String strTable = "1234567890";

        for (int i = 0; i < length; i++) {
            if (i == 0) {
                double dblR = Math.random() * 9;
                int intR = (int) Math.floor(dblR);
                retStr += strTableFirst.charAt(intR);
            } else {
                double dblR = Math.random() * 10;
                int intR = (int) Math.floor(dblR);
                retStr += strTable.charAt(intR);
            }
        }
        return Integer.parseInt(retStr);
    }
}